import 'package:flutter/material.dart';

// form表单项组件
class CommonFormItem extends StatelessWidget {
  final String? label; // 表单标签
  final Widget Function(BuildContext context)? contentBuilder; // 表单内容构造函数

  final Widget? suffix; // 表单后缀内容
  final String? suffixText; // 表单后缀文本

  final String? hintText; // 提示文本
  final ValueChanged<String>? onChanged; // 输入框内容改变回调函数
  final TextEditingController? controller; // 输入框控制器

  const CommonFormItem(
      {super.key,
      this.label,
      this.contentBuilder,
      this.suffix,
      this.suffixText,
      this.hintText,
      this.onChanged,
      this.controller});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding:const EdgeInsets.only(left: 14.0,right: 14.0),
      decoration: const BoxDecoration(
        // Theme.of(context).dividerColor: 从主题中提取分割线颜色
        border: Border(bottom: BorderSide(width: 1.0,color: Color.fromARGB(221, 179, 175, 175)))
      ),
      child: Row(children: [
        SizedBox(
          width: 100.0,
          child: Text(label!,style: const TextStyle(fontSize: 16.0,color: Colors.black87),),
        ),
       Expanded( 
          child: contentBuilder!= null? contentBuilder!(context) : TextField(
          controller: controller,
          decoration: InputDecoration(
            hintText: hintText,
            border: InputBorder.none,
            contentPadding: const EdgeInsets.only(right: 10.0),

          ),
        )),
        if(suffix != null) suffix!,
        if(suffix==null && suffixText != null) Text(suffixText!)
      ]),
    );
  }
}
